package app.kernel.api;

import app.kernel.api.McsAPI;

public class PsgFacade {

	public static McsAPI myPSG = null;
	String myID="";
	
	
	// - Constructor - ID_KEY = http://192.168.10.10:8080/xmlrpc; [ Listening Port ]  
	public PsgFacade(String ID_KEY, String IP, int port){
		
		myPSG = getPSG(ID_KEY, IP, port);
		app.demo.demo.PSGs.put(ID_KEY, myPSG);
		myID = ID_KEY;
	}
	
	public void assign(String domain, String attr, String value){
		
		myPSG.sm.cds.assign(domain, attr, value);
		
	}
	
	public String getContext(String domain, String attr){
		
		return myPSG.sm.cds.getContext(domain, attr);
	}

	// - Leave PSG
	public void leave(String MSID){
		myPSG.sm.leave(myID,MSID);
	}

	// - Register PSG
	public String register(String IPPort){
		return myPSG.sm.register(myID, IPPort);
	}

	
	// - Query MCS	
	public String queryMCS(String query, String ID_KEY){
		
		String res=null;
		try{
			res = QueryClient.queryMCS(query,ID_KEY);
			
		}
		catch(Exception e){
			e.printStackTrace();
		}		
		return res; 
		
	}
	
	
	
	private McsAPI getPSG(String ID_KEY, String nam, int port){
		McsAPI myPSG=null; 
		try{
			 myPSG= new McsAPI(ID_KEY, nam, port);
			 return myPSG;	
		}
		catch(Exception e){
			e.printStackTrace();
			return null;
		}
		
	}
	
	//Ivan 25 June 2010
	public void mobilityUpdate(String MSID, String newIPPort){
		myPSG.sm.mobilityUpdate(myID, MSID, newIPPort);
	}
	
	public String registerCallback(String nam, String callerId, String calleeId){
		return myPSG.sm.registerCallback(nam, callerId, calleeId);
	}
	
	public String withdrawCallback(String nam, String callerId, String calleeId){
		return myPSG.sm.withdrawCallback(nam, callerId, calleeId);
	}
	public String getIPPort(String nam, String MSID){
		return myPSG.sm.getIPPort(nam, MSID);
	}
	
}
